package com.zhao.redis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

//jedis操作键相关的指令
public class TestKey {

    private Jedis jedis;

    @Before
    public void before() {
        jedis = new Jedis("192.168.200.120", 6379);
    }

    @After
    public void after() {
        jedis.close();
    }

    @Test
    public void testKeys() {
        jedis.keys("*");
    }

    @Test
    public void testDel() {
        //删除一个key
        jedis.del("name");
        //删除多个key
//        jedis.del("name", "name1");
    }

    @Test
    public void testExists() {
        boolean name = jedis.exists("name");
        System.out.println(name);
    }

    @Test
    public void testExpire() {
        long name = jedis.expire("name", 20);
        System.out.println(name);
    }

    @Test
    public void testTtl() {
        long name = jedis.ttl("name");
        System.out.println(name);
    }

    @Test
    public void testType() {
        String name = jedis.type("name");
        System.out.println(name);
    }

    @Test
    public void testRandomkey() {
        String key = jedis.randomKey();
        System.out.println(key);
    }

    @Test
    public void testReNamekey() {
        String result = jedis.rename("name", "name1");
        System.out.println(result);
    }
}
